package com.pluszg.nutrition.model.account;

import com.pluszg.nutrition.common.bean.BaseModel;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;


/**
 * plus_account 账户表
 *
 * @author Plus
 * @version 1.0
 * @date 2020-04-29 21:24:15
 * @company pluszg
 */
@SuppressWarnings("serial")
@Setter
@Getter
public class Account extends BaseModel {

    /**
     * id
     */
    private String id;

    /**
     * 账户编码
     */

    private String accountCode;

    /**
     * 账户名称
     */

    private String accountName;

    /**
     * 金额
     */

    private BigDecimal amount;


    public String toString() {
        return new StringBuilder().append("Account{").
                append("id=").append(id).
                append(",accountCode=").append(accountCode).
                append(",accountName=").append(accountName).
                append(",amount=").append(amount).
                append('}').toString();
    }

    /**
     * 复制字段：
     * id, accountCode, accountName, amount
     */
    public Account copy() {
        Account account = new Account();
        account.id = this.id;
        account.accountCode = this.accountCode;
        account.accountName = this.accountName;
        account.amount = this.amount;
        return account;
    }

    /**
     * 比较字段：
     * id, accountCode, accountName, amount
     */
    public boolean test(Account t) {
        if (t == null) return false;
        return (this.id == null || this.id.equals(t.id))
                && (this.accountCode == null || this.accountCode.equals(t.accountCode))
                && (this.accountName == null || this.accountName.equals(t.accountName))
                && (this.amount == null || this.amount.equals(t.amount))
                ;
    }

    public void update(Account element) {
        if (element == null)
            return;
        if (this.id != null && !this.id.isEmpty()) {
            element.id = this.id;
        }
        if (this.accountCode != null && !this.accountCode.isEmpty()) {
            element.accountCode = this.accountCode;
        }
        if (this.accountName != null && !this.accountName.isEmpty()) {
            element.accountName = this.accountName;
        }
        if (this.amount != null) {
            element.amount = this.amount;
        }
    }
}
